<template>
  <view class="result-container">
    <view class="header">
      <text class="title">查询结果</text>
      <button class="back-btn" @click="goBack">返回</button>
    </view>
    
    <view class="result-content" v-if="companyInfo">
      <view class="company-card">
        <view class="company-basic">
          <text class="company-name">{{companyInfo.name}}</text>
          <text class="company-credit" v-if="companyInfo.creditCode">统一社会信用代码: {{companyInfo.creditCode}}</text>
        </view>
        
        <view class="company-info">
          <view class="info-row">
            <text class="info-label">法定代表人:</text>
            <text class="info-value">{{companyInfo.legalPerson || '未知'}}</text>
          </view>
          <view class="info-row">
            <text class="info-label">成立日期:</text>
            <text class="info-value">{{companyInfo.establishDate || '未知'}}</text>
          </view>
          <view class="info-row">
            <text class="info-label">注册资本:</text>
            <text class="info-value">{{companyInfo.registeredCapital || '未知'}}</text>
          </view>
          <view class="info-row">
            <text class="info-label">企业类型:</text>
            <text class="info-value">{{companyInfo.companyType || '未知'}}</text>
          </view>
          <view class="info-row">
            <text class="info-label">经营状态:</text>
            <text class="info-value status-{{companyInfo.status.toLowerCase()}}">{{companyInfo.status || '未知'}}</text>
          </view>
        </view>
      </view>
      
      <view class="company-detail" v-if="showDetail">
        <view class="detail-section">
          <text class="section-title">经营范围</text>
          <text class="section-content">{{companyInfo.businessScope || '暂无数据'}}</text>
        </view>
        
        <view class="detail-section">
          <text class="section-title">注册地址</text>
          <text class="section-content">{{companyInfo.address || '暂无数据'}}</text>
        </view>
      </view>
      
      <button class="detail-btn" @click="toggleDetail">{{showDetail ? '收起详情' : '查看详情'}}</button>
      
      <button class="contact-btn" @click="contactCompany">联系该企业</button>
    </view>
    
    <view class="no-result" v-else-if="!loading">
      <text class="no-result-text">未找到相关企业信息</text>
      <button class="search-again-btn" @click="searchAgain">重新搜索</button>
    </view>
    
    <view class="loading" v-if="loading">
      <div class="loading-spinner"></div>
      <text class="loading-text">查询中...</text>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      companyInfo: null,
      showDetail: false,
      loading: true,
      keyword: ''
    }
  },
  onLoad(options) {
    // 获取传递的关键词参数
    this.keyword = options.keyword || ''
    this.searchCompany()
  },
  methods: {
    searchCompany() {
      if (!this.keyword) {
        this.loading = false
        return
      }
      
      // 模拟API请求
      setTimeout(() => {
        // 模拟企业数据（实际项目中应该从后端获取）
        this.companyInfo = {
          name: this.keyword,
          creditCode: '91110105MA00C6QN7T',
          legalPerson: '张三',
          establishDate: '2018-01-15',
          registeredCapital: '1000万人民币',
          companyType: '有限责任公司',
          status: '存续',
          businessScope: '技术开发、技术咨询、技术服务、技术转让；计算机系统服务；基础软件服务；应用软件服务；数据处理（数据处理中的银行卡中心、PUE值在1.4以上的云计算数据中心除外）；计算机维修；销售计算机、软件及辅助设备、电子产品、机械设备、通讯设备；货物进出口、技术进出口、代理进出口。（企业依法自主选择经营项目，开展经营活动；依法须经批准的项目，经相关部门批准后依批准的内容开展经营活动；不得从事本市产业政策禁止和限制类项目的经营活动。）',
          address: '北京市朝阳区XX大厦A座1001室'
        }
        
        this.loading = false
      }, 1500)
    },
    
    toggleDetail() {
      this.showDetail = !this.showDetail
    },
    
    goBack() {
      window.history.back()
    },
    
    searchAgain() {
      window.location.href = '/pages/index/index'
    },
    
    contactCompany() {
      alert('功能开发中，敬请期待！')
    }
  }
}
</script>

<style scoped>
/* 使用CSS变量保持与全局样式一致性 */
.result-container {
  padding: 16px;
  width: 100%;
  min-height: 100vh;
  background-color: var(--bg-color);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.back-btn {
  padding: 8px 16px;
  background-color: #f0f0f0;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.result-content {
  background-color: var(--white);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.company-card {
  margin-bottom: 16px;
}

.company-basic {
  margin-bottom: 20px;
  text-align: center;
  padding: 10px;
  background-color: #f8f8f8;
  border-radius: 8px;
}

.company-name {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.4;
}

.company-credit {
  font-size: 12px;
  color: var(--text-tertiary);
  word-break: break-all;
}

.company-info {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.info-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.info-label {
  font-size: 13px;
  color: var(--text-tertiary);
}

.info-value {
  font-size: 14px;
  color: var(--text-secondary);
}

.status-存续 {
  color: #07c160;
  font-weight: 500;
}

.status-吊销 {
  color: #ff6b35;
}

.status-注销 {
  color: #999;
}

.company-detail {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.detail-section {
  margin-bottom: 20px;
}

.detail-section:last-child {
  margin-bottom: 0;
}

.section-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.section-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.detail-btn {
  width: 100%;
  padding: 10px 16px;
  background-color: #f0f0f0;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 16px;
}

.contact-btn {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--primary-color);
  border: none;
  border-radius: 6px;
  font-size: 15px;
  color: var(--white);
  cursor: pointer;
}

/* 按钮点击效果 */
.back-btn:active,
.detail-btn:active {
  background-color: #e0e0e0;
}

.contact-btn:active,
.search-again-btn:active {
  opacity: 0.7;
}

.no-result {
  text-align: center;
  padding: 40px 16px;
  background-color: var(--white);
  border-radius: 8px;
}

.no-result-text {
  display: block;
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.search-again-btn {
  padding: 10px 24px;
  background-color: var(--primary-color);
  border: none;
  border-radius: 6px;
  font-size: 14px;
  color: var(--white);
  cursor: pointer;
}

.loading {
  text-align: center;
  padding: 40px 16px;
  background-color: var(--white);
  border-radius: 8px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 3px solid #f0f0f0;
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* 响应式设计 */
@media screen and (min-width: 768px) {
  .result-container {
    max-width: 768px;
    margin: 0 auto;
  }
  
  .company-info {
    grid-template-columns: 1fr 1fr;
  }
}
</style>